/******************** (C) COPYRIGHT 2010 STMicroelectronics ********************
* File Name          : usb_endp.c
* Author             : MCD Application Team
* Version            : V3.2.1
* Date               : 07/05/2010
* Description        : Endpoint routines
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/

/* Includes ------------------------------------------------------------------*/
#include "usb_lib.h"
#include "usb_desc.h"
#include "usb_istr.h"
#include "usb_pwr.h"
#include "usb_mes_an.h"
#include "protocols.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
uint8_t USB_in_buffer[USB_DATA_SIZE];
__IO uint32_t count_out = 0;
uint32_t count_in = 0;

extern uint8_t selected_protocol;
extern uint8_t mes_needed;

/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/*******************************************************************************
* Function Name  : EP1_IN_Callback
* Description    :
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void EP1_IN_Callback (void)
{
	uint8_t dummy_array[2];
	
	if(count_in > 0)
	{
		PCD_EP_Write(EP1_IN, dummy_array, 0);
		SetEPTxValid(ENDP1);
	}
	
	count_in = 0;		

}


/*******************************************************************************
* Function Name  : EP3_OUT_Callback
* Description    :
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void EP3_OUT_Callback(void)
{
	USB_OTG_EP *ep;
  	/* stop measurement */
 	mes_needed=0;
  
  	ep = PCD_GetOutEP(EP3_OUT);
	count_out = ep->xfer_len;
  	PCD_EP_Read(EP3_OUT, USB_in_buffer, count_out);

  	/* call receive function */
  	if((selected_protocol == 0) &&  (count_out != 0) && ((USB_in_buffer[10])*2 + 34 == count_out))
  	{
		usb_receive(USB_in_buffer);
  	}
  	else if ((selected_protocol ==1) && (count_out == 7))
  	{
		usb_receive(USB_in_buffer);
  	}

}


